package token

import (
	"fmt"
	"src/config"

	"github.com/qiniu/api.v7/v7/auth/qbox"
	"github.com/qiniu/api.v7/v7/storage"
)

var (
	accessKey = config.Conf.Qiniu.AccessKey
	secretKey = config.Conf.Qiniu.SecretKey
	bucket    = config.Conf.Qiniu.Bucket
)

func GetCustomUpToken(keyToOverwrite, persistentOps string, expires uint64) string {
	mac := qbox.NewMac(accessKey, secretKey)

	putPolicy := storage.PutPolicy{
		Scope:         fmt.Sprintf("%s:%s", bucket, keyToOverwrite),
		PersistentOps: persistentOps,
		Expires:       expires,
	}
	return putPolicy.UploadToken(mac)
}
